<template>
	<view>
		<view class="hade">
			<view class="tabnav">
				<navbar background={} backIconColor='#FFFFFF'></navbar>
			</view>
			<view class="hade_img">
				<image :src="pub.con_img" mode=""></image>
			</view>
			<view class="counp_content">
				<height :hg="20"></height>
				<text class="counp_content_title">限时抢券</text>
				<view class="content">
					<view style="margin-top: 150rpx;" v-if="coupon_list.length<1">
						<u-empty mode="data" :iconSize='150' :textSize='24' text='暂无内容' icon=""></u-empty>
					</view>
					<view class="content_box" v-for="(item,index) in coupon_list" :key="item">
						<view style="padding: 20rpx;">
							<view class="content_box_1">
								<view class="content_box_1_left">
									<view>
										{{item.used_amount}}<text style="font-size: 24rpx;">元</text>
									</view>
									<view>
										满{{item.with_amount}}元可用
									</view>
								</view>
								<view class="content_box_1_right">
									<view>
										{{item.title}}
									</view>
									<view>
										{{item.draw_range}}
									</view>
								</view>
							</view>
							<view class="content_box_2">
								<view class="content_box_2_left" @tap="rule(index)">
									<view>使用规则</view>
									<view class="">
										<image src="https://can.clkejj.com/static/Project_drawing 18.png" mode=""></image>
									</view>
								</view>
								<view class="content_box_2_right" v-if="item.status" @tap="coupon_drawApi(item.id)">
									领取
								</view>
								<view class="content_box_2_right" v-else>
									不可领
								</view>
							</view>
							<view class="rule" v-show="item.show">
								{{item.remarks}}
							</view>
						</view>
					</view>
					<height :hg="20"></height>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		coupon_couponList,
		coupon_draw
	} from "@/api/comm.js"
	export default {
		data() {
			return {
				coupon_list: [],
				pub: uni.getStorageSync('public')
			};
		},
		onLoad() {
			this.coupon_couponListApi()
			if (!uni.getStorageSync('userinfo')) {
				this.enter = true
				uni.showToast({
					title: '未登录',
					icon: 'none'
				})
				return
			}
		},
		onShow() {
			if (!uni.getStorageSync('userinfo')) {
				this.enter = true
				uni.showToast({
					title: '未登录',
					icon: 'none'
				})
				return
			} else {
				this.enter = false
			}
		},
		methods: {
			async coupon_couponListApi() {
				let data = await coupon_couponList()
				this.coupon_list = []
				this.coupon_list.push(...data.data)
			},
			rule(index) {
				if (this.coupon_list[index].show) {
					this.coupon_list[index].show = 0
				} else {
					this.coupon_list[index].show = 1
				}
			},
			async coupon_drawApi(id) {
				let data = await coupon_draw({
					id
				})
				if (data.code == 1) {
					this.coupon_couponListApi()
					uni.showToast({
						title: data.msg,
						icon: "success"
					})
				} else {
					uni.showToast({
						title: data.msg,
						icon: "error"
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.hade {
		position: relative;

		.tabnav {
			width: 100%;
			position: absolute;
			top: 0;
			z-index: 2;
		}

		.hade_img {
			width: 100%;
			height: 682rpx;
		}

		.counp_content {
			background: #F4F5F7;
			border-radius: 38rpx 38rpx 0rpx 0rpx;
			position: relative;
			bottom: 60rpx;

			.counp_content_title {
				font-size: 36rpx;
				font-weight: 500;
				color: #3A3A3A;
				padding: 30rpx 30rpx;
			}

			.content_box {
				width: 702rpx;
				height: 230rpx;
				background: #FFFFFF;
				margin: 20rpx auto;
				border-radius: 20rpx;

				.content_box_1 {
					display: flex;
					align-items: center;

					.content_box_1_left {
						text-align: center;
						padding-left: 20rpx;
						padding-top: 20rpx;

						view:nth-child(1) {
							font-size: 40rpx;
							font-weight: 600;
							color: #FC3B4C;
						}

						view:nth-child(2) {
							font-size: 24rpx;
							font-weight: 400;
							color: #979797;
						}
					}

					.content_box_1_right {
						padding-left: 40rpx;
						padding-top: 30rpx;

						view:nth-child(1) {
							font-size: 32rpx;
							font-weight: 600;
							color: #3A3A3A;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}

						view:nth-child(2) {
							font-size: 24rpx;
							font-weight: 400;
							color: #A0A0A0;
						}
					}
				}

				.content_box_2 {
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-top: 1rpx solid #F6F6F6;
					margin-top: 20rpx;
					padding-top: 15rpx;

					.content_box_2_left {
						display: flex;
						align-items: center;

						view:nth-child(1) {
							font-size: 24rpx;
							font-weight: 400;
							color: #343434;
						}

						view:nth-child(2) {
							width: 33rpx;
							height: 33rpx;
							margin-left: 10rpx;
						}
					}

					.content_box_2_right {
						width: 151rpx;
						height: 58rpx;
						background: #6F3810;
						border-radius: 29rpx;

						font-size: 24rpx;
						font-weight: 400;
						color: #FFFFFF;
						line-height: 58rpx;
						text-align: center;
					}
				}

				.rule {
					width: 299rpx;
					background: #FFFFFF;
					box-shadow: 0rpx 2rpx 10rpx 0rpx rgba(0, 0, 0, 0.13);
					border-radius: 8rpx;
					position: relative;
					bottom: 5rpx;
					left: -20rpx;
					padding: 20rpx 20rpx;
					font-size: 24rpx;
					font-weight: 400;
					color: #A0A0A0;
				}
			}
		}
	}
</style>